-- @owner: @taoying
-- @date: 2025-09-17
-- @testpoint: objectproperty函数IsTrigger测试，合理报错
-- @modify: 

--step1:连接兼容D库创建数据库
@conn PrimaryDbDmode;
--step2:删除插件
create extension if not exists shark;
--step3:执行测试
DROP TABLE if exists user_log;
CREATE TABLE user_log (
id SERIAL PRIMARY KEY,
username VARCHAR(50),
email VARCHAR(100),
action_type VARCHAR(10),
action_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE OR REPLACE FUNCTION log_user_actions()
RETURNS TRIGGER AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
INSERT INTO user_log (username, email, action_type)
VALUES (NEW.username, NEW.email, 'INSERT');
RETURN NEW;
ELSIF TG_OP = 'UPDATE' THEN
INSERT INTO user_log (username, email, action_type)
VALUES (NEW.username, NEW.email, 'UPDATE');
RETURN NEW;
ELSIF TG_OP = 'DELETE' THEN
INSERT INTO user_log (username, email, action_type)
VALUES (OLD.username, OLD.email, 'DELETE');
RETURN OLD;
END IF;
END;
$$ LANGUAGE plpgsql;
/

drop TRIGGER if exists users_trigger on public.user_log;
CREATE TRIGGER users_trigger
AFTER INSERT OR UPDATE OR DELETE ON user_log
FOR EACH ROW EXECUTE FUNCTION log_user_actions();
/

select OBJECTPROPERTY (OBJECT_ID('users_trigger'), 'IsTrigger');
select OBJECTPROPERTY (OBJECT_ID('users_trigger'));
select OBJECTPROPERTY (OBJECT_ID('users_trigger','TR'), 'IsTrigger');
select OBJECTPROPERTY (OBJECT_ID('users_trigger','FN'), 'IsTrigger');
select OBJECTPROPERTY (OBJECT_ID('users_trigger'), 'IsTableFunction');
select OBJECTPROPERTY (OBJECT_ID('users_trigger'), 'OwnerId');
select OBJECTPROPERTY ('user_log', ' OwnerId');
select OBJECTPROPERTY ('', ' IsTrigger');
select OBJECTPROPERTY ('IsTrigger');
--step4:清理环境
drop TABLE if exists user_log;
drop TABLE if exists public.user_log;
drop TRIGGER if exists users_trigger on public.user_log;
drop FUNCTION if exists log_user_actions;